home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
...taking it to the Macs!
/
...taking it to the Macs!.iso
/
Extras
/
ActiveX Mac SDK
/
ActiveX SDK
/
Container Common
/
CBindHost.cpp
< prev
next >
Wrap
Text File
|
1997-01-03
|
10KB
|
610 lines
//
// CBindHost.cpp
//
// The Hook BSC for reporting Progress on IBindHost initiated
// bindings.
//
// Copyright (C) Microsoft Corporation, 1996
//
#include "headers.h"
#include "urlapi.h"
#pragma mark === CBindHost Methods ===
//
// CBindHost::CBindHost
//
CBindHost::CBindHost(CXSite* pSite)
: mRefCount(1), mSite(pSite), mBSCList(0)
{
}
//
// CBindHost::~CBindHost
//
CBindHost::~CBindHost()
{
}
#pragma mark === CBindHost::IUnknown Interface ===
//
// CBindHost::IUnknown::QueryInterface
//
STDMETHODIMP CBindHost::QueryInterface(REFIID riid, LPVOID *ppvObj)
{
return mSite->QueryInterface(riid, ppvObj);
}
//
// CBindHost::IUnknown::AddRef
//
STDMETHODIMP_(ULONG) CBindHost::AddRef(void)
{
++mRefCount;
return mSite->AddRef();
}
//
// CBindHost::IUnknown::Release
//
STDMETHODIMP_(ULONG) CBindHost::Release(void)
{
--mRefCount;
return mSite->Release();
}
#pragma mark === CBindHost::IBindHost Interface ===
//
// CBindHost::IBindHost::CreateMoniker
//
STDMETHODIMP CBindHost::CreateMoniker(LPOLESTR szName, IBindCtx * /* pBC */, IMoniker **ppmk, DWORD /* dwReserved */)
{
HRESULT hr = NOERROR;
IURLMoniker* pmk;
LPOLESTR ResolvedName;
if ((ResolvedName = x_ExpandRelativeAnchor(szName, mSite->m_BaseURL)) == NULL)
return E_OUTOFMEMORY;
#if defined(PLUGIN_ADAPTER)
pmk = (IURLMoniker*) new CXURLMoniker(mSite, ResolvedName);
if(!pmk)
hr = E_OUTOFMEMORY;
#else
hr = CreateURLMoniker(NULL, ResolvedName, &pmk);
CoTaskMemFree(ResolvedName);
#endif
if (hr == NOERROR)
{
*ppmk = (LPMONIKER) pmk;
}
else
{
*ppmk = NULL;
}
return hr;
}
//
// CBindHost::IBindHost::MonikerBindToStorage
//
STDMETHODIMP CBindHost::MonikerBindToStorage(
IMoniker *pMk,
IBindCtx *pBC,
IBindStatusCallback *pBSC,
REFIID riid,
void **ppvObj)
{
return MonikerBind(pMk, pBC, pBSC, riid, ppvObj, FALSE);
}
//
// CBindHost::IBindHost::MonikerBindToObject
//
STDMETHODIMP CBindHost::MonikerBindToObject(
IMoniker *pMk,
IBindCtx *pBC,
IBindStatusCallback *pBSC,
REFIID riid,
void **ppvObj)
{
return MonikerBind(pMk, pBC, pBSC, riid, ppvObj, TRUE);
}
#pragma mark === CBindHost Helper Methods ===
//
// CBindHost::MonikerBind
//
STDMETHODIMP CBindHost::MonikerBind(
IMoniker *pMk,
IBindCtx *pBC,
IBindStatusCallback *pBSC,
REFIID riid,
void **ppvObj,
BOOL fObject)
{
HRESULT hr = NOERROR;
IBindCtx *pBndCtx = pBC;
CBindHostBSC* pBSCHook = NULL;
if (!pMk || !ppvObj)
{
hr = E_INVALIDARG;
goto Done;
}
if (pBndCtx == NULL)
{
hr = CreateBindCtx(0, &pBndCtx);
}
if (pBSC != NULL)
{
hr = AddClient(pBSC, &pBSCHook);
if (SUCCEEDED(hr))
{
hr = pBndCtx->RegisterObjectParam(REG_BSCB_HOLDER, (LPUNKNOWN) pBSCHook);
if ( SUCCEEDED(hr) )
pBSCHook->Release();
hr = pBndCtx->RegisterObjectParam(REG_ISL_CLIENT, (IContainerSite*) mSite);
}
}
// if not our bind context addref it!
if (pBC != NULL && pBSCHook)
{
pBC->AddRef();
}
if (hr == NOERROR)
{
if (fObject)
{
hr = pMk->BindToObject(pBndCtx, NULL, riid, ppvObj);
}
else
{
hr = pMk->BindToStorage(pBndCtx, NULL, riid, ppvObj);
}
}
Done:
#if 0
if (hr != MK_S_ASYNCHRONOUS) {
// binding either failed or completed synchronously
if (pBSCHook)
{
HRESULT hr1 = RemoveClient(pBSCHook);
if (FAILED(hr1)) {
hr = hr1;
}
}
}
#endif
return hr;
}
//
// CBindHost::AddClient
//
HRESULT
CBindHost::AddClient(IBindStatusCallback *pClientBSC, CBindHostBSC **ppBSCHook)
{
ASSERT(pClientBSC);
HRESULT hr = S_OK;
*ppBSCHook = new CBindHostBSC(this, pClientBSC);
if (!*ppBSCHook) {
hr = E_OUTOFMEMORY;
return hr;
}
if(mBSCList == NULL)
mBSCList = new LArray( sizeof(void*));
AddBSC(*ppBSCHook);
pClientBSC->AddRef();
return hr;
}
//
// CBindHost::RemoveClient
//
HRESULT
CBindHost::RemoveClient(CBindHostBSC *pBSCHook)
{
if(mBSCList == NULL)
return E_FAIL;
RemoveBSC(pBSCHook);
pBSCHook->Release();
return S_OK;
}
//
// CBindHost::AbortBindings
//
HRESULT
CBindHost::AbortBindings()
{
// iterate through all BSCs
int iNum = GetCount() ;
for (int i=1; i <= iNum; i++)
{
CBindHostBSC *pBSCHook = GetBSC(i);
ASSERT(pBSCHook != NULL);
if (pBSCHook)
pBSCHook->Abort();
}
return S_OK;
}
#pragma mark === CBindHost Utility Methods ===
//
// CBindHost::AddBSC
//
void
CBindHost::AddBSC(CBindHostBSC *Host)
{
mBSCList->InsertItemsAt(1, 0x7fffffff, &Host);
}
//
// CBindHost::RemoveBSC
//
void
CBindHost::RemoveBSC(CBindHostBSC *Host)
{
mBSCList->Remove(&Host);
}
//
// CBindHost::GetCount
//
unsigned long
CBindHost::GetCount(void)
{
return mBSCList ? mBSCList->GetCount() : 0;
}
//
// CBindHost::GetCount
//
unsigned long
CBindHost::FindBSC(CBindHostBSC* Host)
{
return mBSCList->FetchIndexOf(Host);
}
//
// CBindHost::GetBSC
//
CBindHostBSC* CBindHost::GetBSC(unsigned long Index)
{
CBindHostBSC* Host = NULL;
mBSCList->FetchItemAt(Index, &Host);
return Host;
}
#pragma mark === CBindHostBSC Methods ===
//
// CBindHostBSC::CBindHostBSC
//
CBindHostBSC::CBindHostBSC(CBindHost *pBindHost, IBindStatusCallback *pClientBSC):m_pBindHost(pBindHost), m_RefCount(1), m_pBinding(NULL), m_pClientBSC(pClientBSC), m_pbc(NULL)
{
}
//
// CBindHostBSC::~CBindHostBSC
//
CBindHostBSC::~CBindHostBSC()
{
if (m_pBinding)
SAFERELEASE(m_pBinding);
if (m_pClientBSC)
SAFERELEASE(m_pClientBSC);
// if (m_pbc)
// SAFERELEASE(m_pbc);
}
//
// CBindHostBSC::Abort
//
HRESULT
CBindHostBSC::Abort(void)
{
if (m_pBinding)
m_pBinding->Abort();
return S_OK;
}
#pragma mark === CBindHostBSC IUnknown Interface ===
//
// CBindHostBSC::IUnknown::QueryInterface
//
STDMETHODIMP
CBindHostBSC::QueryInterface( REFIID riid, LPVOID *ppv )
{
ASSERT(ppv != NULL);
if (ppv == NULL)
return E_INVALIDARG;
*ppv = NULL;
if( riid == IID_IUnknown)
*ppv = this;
else if (riid == IID_IBindStatusCallback)
*ppv = (IBindStatusCallback *)this;
else if (riid == IID_IServiceProvider)
*ppv = (IServiceProvider *) this;
else
return E_NOINTERFACE;
((IUnknown *)*ppv)->AddRef();
return S_OK;
}
//
// CBindHostBSC::IUnknown::AddRef
//
STDMETHODIMP_(ULONG)
CBindHostBSC::AddRef()
{
return(++m_RefCount);
}
//
// CBindHostBSC::IUnknown::Release
//
STDMETHODIMP_(ULONG)
CBindHostBSC::Release()
{
if(--m_RefCount==0) {
delete this;
return(0);
}
return( m_RefCount );
}
#pragma mark === CBindHostBSC IBindStatusCallback Interface ===
//
// CBindHostBSC::IBindStatusCallback::GetBindInfo
//
STDMETHODIMP
CBindHostBSC::GetBindInfo( DWORD *grfBINDF, BINDINFO *pbindInfo)
{
#if 0
PMWIN pMwin = NULL;
IUnknown *pIUnk = NULL;
ASSERT((grfBINDF != NULL) && (pbindInfo != NULL));
if ((grfBINDF == NULL) || (pbindInfo == NULL))
return E_INVALIDARG;
pIUnk = m_pBindHost->GetHTMLObj();
pMwin = ((HTMLObj *)(IMsoCommandTarget*)pIUnk)->GetDocMWin();
if ((pMwin) && (pMwin->flags & TW_LD_FL_REFRESH))
*grfBINDF |= BINDF_RESYNCHRONIZE;
if ((pMwin) && (pMwin->flags & TW_LD_FL_REFRESH_ALL)) {
*grfBINDF &= ~BINDF_RESYNCHRONIZE;
*grfBINDF |= BINDF_GETNEWESTVERSION;
}
#endif
return m_pClientBSC->GetBindInfo(grfBINDF, pbindInfo);
}
//
// CBindHostBSC::IBindStatusCallback::OnStartBinding
//
STDMETHODIMP
CBindHostBSC::OnStartBinding(DWORD grfBSCOption,IBinding *pib)
{
ASSERT(pib != NULL);
if (pib == NULL)
return E_INVALIDARG;
m_pBinding = pib;
pib->AddRef();
return m_pClientBSC->OnStartBinding(grfBSCOption, pib);
}
//
// CBindHostBSC::IBindStatusCallback::GetPriority
//
STDMETHODIMP
CBindHostBSC::GetPriority( LONG *pnPriority)
{
return m_pClientBSC->GetPriority(pnPriority);
}
//
// CBindHostBSC::IBindStatusCallback::OnProgress
//
STDMETHODIMP
CBindHostBSC::OnProgress
(
ULONG ulProgress,
ULONG ulProgressMax,
ULONG ulStatusCode,
LPCOLESTR pwzStatusText
)
{
#if 0
char szMsg[MAX_URL_STRING + 15];
PMWIN pmwin = ((HTMLObj *)(IMsoCommandTarget*)m_pBindHost->GetHTMLObj())->GetDocMWin();
char *lpszStatusText = NULL;
switch (ulStatusCode)
{
case (BINDSTATUS_DOWNLOADINGDATA):
Unicode2Ansi(pwzStatusText, &lpszStatusText);
if (lpszStatusText)
{
GTR_formatmsg(RES_STRING_MAPCACHE1,szMsg,sizeof(szMsg),lpszStatusText);
if (!m_bWaitPushed) {
WAIT_Push(pmwin, waitFullInteract, (unsigned char *)szMsg);
m_bWaitPushed = TRUE;
}
HTMLObj_SetStatusText(((IMsoCommandTarget*)m_pBindHost->GetHTMLObj())
,szMsg, FALSE);
GTR_FREE(lpszStatusText);
}
{
// BUGBUG DavidMay 8/1/96: If the host's progress bar had higher
// resolution, you might want to send these more often than every
// 5 percent, but for the current progress bar, it's more than enough.
// Sending it every time caused enough message traffic to lock up
// NT machines downloading large files over fast links.
int iPercent = MulDiv(ulProgress, 100, ulProgressMax);
if (iPercent > m_LastProgressSent + 5)
{
WAIT_SetRange (pmwin, 0, 100, ulProgressMax);
WAIT_SetTherm (pmwin, ulProgress);
m_LastProgressSent = iPercent;
}
}
break;
default:
break;
}
#endif
return m_pClientBSC->OnProgress(ulProgress, ulProgressMax, ulStatusCode,
pwzStatusText);
}
//
// CBindHostBSC::IBindStatusCallback::OnDataAvailable
//
STDMETHODIMP
CBindHostBSC::OnDataAvailable
(
DWORD grfBSCF,
DWORD dwSize,
FORMATETC * pFmtetc,
STGMEDIUM * pstgmed
)
{
return m_pClientBSC->OnDataAvailable(grfBSCF, dwSize, pFmtetc, pstgmed);
}
//
// CBindHostBSC::IBindStatusCallback::OnObjectAvailable
//
STDMETHODIMP
CBindHostBSC::OnObjectAvailable ( REFIID riid, LPUNKNOWN pUnk)
{
return m_pClientBSC->OnObjectAvailable(riid, pUnk);
}
//
// CBindHostBSC::IBindStatusCallback::OnLowResource
//
STDMETHODIMP
CBindHostBSC::OnLowResource( DWORD reserved)
{
return m_pClientBSC->OnLowResource(reserved);
}
//
// CBindHostBSC::IBindStatusCallback::OnStopBinding
//
STDMETHODIMP
CBindHostBSC::OnStopBinding(HRESULT hrError, LPCOLESTR szError)
{
HRESULT hr = S_OK;
#if 0
PMWIN pmwin = ((HTMLObj *)(IMsoCommandTarget*)m_pBindHost->GetHTMLObj())->GetDocMWin();
HTMLObj_SetStatusText(((IMsoCommandTarget*)m_pBindHost->GetHTMLObj()), "", FALSE);
if (m_bWaitPushed) {
WAIT_Pop(pmwin);
m_bWaitPushed = FALSE;
}
RevokeBindStatusCallback(m_pbc, this);
#endif
SAFERELEASE(m_pBinding);
hr = m_pClientBSC->OnStopBinding(hrError, szError);
SAFERELEASE(m_pClientBSC);
// if (m_pbc)
// SAFERELEASE(m_pbc);
m_pBindHost->RemoveClient(this);
return hr;
}